package com.boyue.web.controller;

import com.boyue.entity.AddressList;
import com.boyue.service.AddressListService;
import com.boyue.service.impl.AddressListServiceImpl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.SQLException;
import java.util.List;

/**
 * @auth wzy
 * @date 2023/9/2 15:42
 */
public class AddressListController {

    private AddressListService service = new AddressListServiceImpl();

    public String list(HttpServletRequest request, HttpServletResponse response){
        try {
            List<AddressList> list = service.list();

            request.setAttribute("list", list);

            return "/addresslist.jsp";
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return "error.jsp";
    }

    public String delete(HttpServletRequest request, HttpServletResponse response){
        String id = request.getParameter("id");

        try {
            Integer result = service.delete(Integer.valueOf(id));
            if (result >0){
                return "redirect:/do/addresslist/list";
            } else {
                return "/error.jsp";
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return "/error.jsp";
    }
}
